package com.attendance.www.hr.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.attendance.www.hr.beans.CheckinoutMorningBean;
import com.attendance.www.hr.beans.UserEmployeeBean;
import com.attendance.www.hr.constant.AppConstant;
import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.ICheckinoutMorningService;
import com.zhangkongli.frame.core.ResultMap;

/**
 * 早上打卡记录
 * @author 张鑫
 * 2018-03-29
 */
@Controller
@RequestMapping("/checkinoutMorning")
public class CheckinoutMorningController {
	
	@Resource
	private ICheckinoutMorningService checkinoutMorningService;
	
	/**
	 * 查询早上打卡记录
	 * @param request
	 * @param checkinoutMorningBean
	 * @return
	 */
	@RequestMapping(value = "/getCheckinoutMorningList.do", method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public Object getCheckinoutMorningList(HttpServletRequest request, @RequestBody CheckinoutMorningBean checkinoutMorningBean){
		if (checkinoutMorningBean.getAttendanceDate()==null) {
			throw new ResultFaultException("0_00001");
		}
		//获取登录用户
		UserEmployeeBean userEmployee = (UserEmployeeBean) request.getSession().getAttribute(AppConstant.SESSIONUSER);
		if (userEmployee == null) {
			throw new ResultFaultException("1_00001");
		}
		checkinoutMorningBean.setEmployeeId(userEmployee.getEmployeeId());
		return ResultMap.success(checkinoutMorningService.getCheckinoutMorningList(checkinoutMorningBean));
	}

	/**
	 * 查7：30前有没有打卡时间
	 * @param request
	 * @param checkinoutMorningBean
	 * @return 1有，0没有
	 */
	@RequestMapping(value = "/getMorningTime.do", method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public Object getMorningTime(HttpServletRequest request, @RequestBody CheckinoutMorningBean checkinoutMorningBean){
		if (checkinoutMorningBean.getAttendanceDate()==null) {
			throw new ResultFaultException("0_00001");
		}
		//获取登录用户
		UserEmployeeBean userEmployee = (UserEmployeeBean) request.getSession().getAttribute(AppConstant.SESSIONUSER);
		if (userEmployee == null) {
			throw new ResultFaultException("1_00001");
		}
		checkinoutMorningBean.setEmployeeId(userEmployee.getEmployeeId());
		return ResultMap.success(checkinoutMorningService.getMorningTime(checkinoutMorningBean));
	}
}
